using System;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace TXLooker.Common
{
    public class LogManager
    {
        private static string CustomLogFilePath
        {
            get
            {
                if (m_path == null)
                {
                    string lookerLogsDirectory = Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                        "Looker"
                    );

                    if (!Directory.Exists(lookerLogsDirectory)) Directory.CreateDirectory(lookerLogsDirectory);
                    m_path = Path.Combine(lookerLogsDirectory , "Looker.log");
                }

                return m_path;
            }
        }
        private static string m_path = null;
        private static Logging logManager = new Logging(CustomLogFilePath, 3000000);
        public static void WriteMessageToCustomLog(string msg)
        {
            logManager.WriteToCustomLog(DateTime.Now+ ": "+ msg);
        }
        public static void WriteMessageToCustomLog(Exception ex)
        {
            WriteMessageToCustomLog(ex.ToString());
        }
        public static Encoding Encoding
        {
            get { return m_encoding; }
            set { m_encoding = value; }
        }
        private static Encoding m_encoding = System.Text.Encoding.Default;
        /// <summary>
        /// Write message to System Event Log
        /// </summary>
        public static void WriteMessageToEventLog( string sourceName, Exception ce )
        {
            WriteMessageToEventLog(sourceName,ce.ToString(), EventLogEntryType.Error);
        }
        /// <summary>
        /// Write message to System Event Log
        /// </summary>
        public static void WriteMessageToEventLog(string sourceName, string msg, EventLogEntryType type)
        {
            logManager.WriteToEventLog(msg, sourceName, type);
        }
    }
}
